<?php
/**
 * Created by PhpStorm.
 * User: Egg
 * Date: 2018/3/20
 * Time: 13:36
 */

namespace Home\Model;


class UserAuthLogic
{
    /**
     * 生成销售员申请模板
     * @param $openId   审核员(经销商)的openid
     * @param $saleInfo 导购员信息
     * @return string 待发送的模板字符串
     */
    public function createSalerTemplateData($openId, $saleInfo)
    {
        $templateId = C('sale_template_id');
        $dataJson = '"data":{
                   "head_msg": {
                       "value":"您有一条申请消息！",
                       "color":"#ff0000"
                   },
                   "saler_name":{
                       "value":"'.$saleInfo['nickname'].'",
                       "color":"#173177"
                   },
                   "saler_tel": {
                       "value":"'.$saleInfo['tel'].'",
                       "color":"#173177"
                   },
                   "time": {
                       "value":"' . date("Y-m-d") . '",
                       "color":"#173177"
                   },
                   "remark":{
                       "value":"",
                       "color":"#173177"
                   }
           }';
        $data = ' {
           "touser":"' . $openId . '",
           "template_id":"' . $templateId . '",
           "url":"' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'] . '/Home/UserAuth/saleAuthShow?sid=' . $saleInfo['id'] . '", ' .
            $dataJson .
            '
       }';
        return $data;
    }

    /**
     * 生成审核成功模板
     * @param $openId   申请人(导购员)的openid
     * @return string   待发送的模板字符串
     */
    public function createAuthTemplateData($openId)
    {
        $templateId = C('auth_template_id');
        $dataJson = '"data":{
           }';
        $data = ' {
           "touser":"' . $openId . '",
           "template_id":"' . $templateId . '",
           "url":"", ' .
            $dataJson .
            '
       }';
        return $data;
    }

    /**
     * 获取用户的openid
     * @param $sid  用户id
     * @return mixed
     */
    public function getOpenid($sid)
    {
        $userInfo = D('Wechat/user')
            ->find($sid);
        return $userInfo['openid'];
    }
}